package com.rotsel.mh3udb.app.Fragments;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.rotsel.mh3udb.app.Activities.WeaponListActivity;
import com.rotsel.mh3udb.app.Adapters.PicTextListItemAdapter;
import com.rotsel.mh3udb.app.R;
import com.rotsel.mh3udb.app.models.WeaponTypeModel;

import java.util.ArrayList;

/**
 * Created by Roman on 30.05.2014.
 */
public class WeaponTypeFragment extends BaseFragment {
    private ListView weaponTypeList;

    @Override
    public void onCreate(Bundle bundle){
        super.onCreate(bundle);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        return inflater.inflate(R.layout.list_view, container, false);
    }

    @Override
    public void onStart(){
        super.onStart();

        final Activity activity = getActivity();
        if (activity == null){
            return;
        }

        ArrayList<WeaponTypeModel> allWeaponTypes = getDb().getAllWeaponTypes();
        PicTextListItemAdapter adapter = new PicTextListItemAdapter(activity.getBaseContext(), allWeaponTypes);

        weaponTypeList = (ListView)getActivity().findViewById(R.id.list);
        weaponTypeList.setAdapter(adapter);
        weaponTypeList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(activity.getBaseContext(), WeaponListActivity.class);
                Bundle b = new Bundle();
                b.putInt("weaponTypeId", (int)id);
                intent.putExtras(b);
                startActivity(intent);
            }
        });

    }
}
